home *** CD-ROM | disk | FTP | other *** search
- //@line 40 "/cygdrive/K/tinderbuild/src/flock/mozilla/browser/components/bookmarks/content/addBookmark2.js"
-
- /**
- * Add Bookmark Dialog.
- * ====================
- *
- * This is a generic bookmark dialog that allows for bookmark addition
- * and folder selection. It can be opened with various parameters that
- * result in appearance/purpose differences and initial state.
- *
- * Use: Open with 'openDialog', with the flags
- * 'centerscreen,chrome,dialog=no,resizable=yes'
- *
- * Parameters:
- * Apart from the standard openDialog parameters, this dialog can
- * be passed additional information, which is contained in the
- * wArg object:
- *
- * wArg.name : Bookmark Name. The value to be prefilled
- * into the "Name: " field (if visible).
- * wArg.description : Bookmark description. The value to be added
- * : to the boomarks description field.
- * wArg.url : Bookmark URL: The location of the bookmark.
- * The value to be filled in the "Location: "
- * field (if visible).
- * wArg.folderURI : Bookmark Folder. The RDF Resource URI of the
- * folder that this bookmark should be created in.
- * wArg.charset : Bookmark Charset. The charset that should be
- * used when adding a bookmark to the specified
- * URL. (Usually the charset of the current
- * document when launching this window).
- * wArg.bBookmarkAllTabs : True if "Bookmark All Tabs" option is chosen,
- * false otherwise.
- * wArg.objGroup[] : If adding a group of tabs, this is an array
- * of wArg objects with name, URL and charset
- * properties, one for each group member.
- * wArg.bWebPanel : If the bookmark should become a web panel.
- * wArg.keyword : A suggested keyword for the bookmark. If this
- * argument is supplied, the keyword row is made
- * visible.
- * wArg.bNeedKeyword : Whether or not a keyword is required to add
- * the bookmark.
- * wArg.postData : PostData to be saved with this bookmark,
- * in the format a string of name=value pairs
- * separated by CRLFs.
- * wArg.feedURL : feed URL for Livemarks (turns bookmark
- * into Livemark)
- */
-
-
- var gName;
- var gKeyword;
- var gKeywordRow;
- var gKeywordRequired;
- var gSuggestedKeyword;
- var gRequiredFields = [];
- var gPostData;
- var gArg = window.arguments[0];
- var gResource;
- var gDescription;
- var gTags;
- var gFavorites = [];
- var gType;
- var gPerson; // TODO make array later for multiple potential friends
-
- //@line 106 "/cygdrive/K/tinderbuild/src/flock/mozilla/browser/components/bookmarks/content/addBookmark2.js"
-
-
- function Startup()
- {
- initServices();
- initBMService();
-
- var pref_service = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
- var prefsService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
- $("showDialog").checked = prefsService.getBoolPref("flock.favorites.starShowProperties");
- // document.getElementById("flock_share_enable").value = "Log into a supported Favorites sharing service," +
- // "and option for sharing your Favorites online and sharing them with others will appear here";
- gName = document.getElementById("name");
- gKeywordRow = document.getElementById("keywordRow");
- gKeyword = document.getElementById("keyword");
- gExpander = document.getElementById("expander");
- gBookmarksTree = document.getElementById("folder-tree");
- gDescription = document.getElementById("description");
- gDescription.value = gArg.description;
- gTags = document.getElementById("tags");
- gTags.value = gArg.tags;
- gName.value = gArg.name;
- gName.focus();
- gFavorites = gArg.favorites;
- gType = gArg.type;
- gSuggestedKeyword = gArg.keyword;
- gKeywordRequired = gArg.bNeedKeyword;
-
- if(!loadShareArea($('bmServices-box'), gArg.url, true))
- {
- loadDoEverytime();
- }
- if (!gSuggestedKeyword && !gKeywordRequired) {
- gKeywordRow.hidden = true;
- } else {
- if (gSuggestedKeyword)
- gKeyword.value = gSuggestedKeyword;
- if (gKeywordRequired)
- {
- gRequiredFields.push(gKeyword);
- $("descriptionRow").setAttribute('hidden', 'true');
- $("tagsRow").setAttribute('hidden', 'true');
- $('shareArea').setAttribute('hidden', 'true');
- $('createlocalcheck').setAttribute('checked', 'true');
- $('createlocalcheck').setAttribute('disabled', 'true');
- $("AdvancedFeatures").setAttribute("hidden", true);
- }
- }
-
- if ("feedURL" in gArg) {
- var strings = document.getElementById("bookmarksBundle");
- document.title = strings.getString("addLiveBookmarkTitle");
- $('shareArea').setAttribute('hidden', 'true');
- $('tagsRow').setAttribute('hidden', 'true');
- $("createlocalcheck").setAttribute("disabled", true);
- $("AdvancedFeatures").setAttribute("hidden", true);
- }
-
- sizeToContent();
- onFieldInput();
- initTitle();
- // loadValues();
- gExpander.setAttribute("tooltiptext", gExpander.getAttribute("tooltiptextdown"));
- gPostData = gArg.postData;
-
- //@line 172 "/cygdrive/K/tinderbuild/src/flock/mozilla/browser/components/bookmarks/content/addBookmark2.js"
- WSucks = parseInt(gBookmarksTree.getAttribute("height"));
- if (!WSucks)
- WSucks = 150;
-
- // fix no more persisted class attribute in old profiles
- var localStore = RDF.GetDataSource("rdf:local-store");
- var rAttribute = RDF.GetResource("class");
- var rElement = RDF.GetResource("chrome://browser/content/bookmarks/addBookmark2.xul#expander");
- var rDialog = RDF.GetResource("chrome://browser/content/bookmarks/addBookmark2.xul");
- var rPersist = RDF.GetResource(gNC_NS+"persist");
-
- var rOldValue = localStore.GetTarget(rElement, rAttribute, true);
- if (rOldValue) {
- localStore.Unassert(rElement, rAttribute, rOldValue, true);
- localStore.Unassert(rDialog, rPersist, rElement, true);
- gExpander.setAttribute("class", "down");
- }
-
- // Select the specified folder after the window is made visible
-
- setTimeout(initMenulist, 0);
-
- // Update the "show this dialog" checkbox
- var prefsService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
- var starShowProperties = prefsService.getBoolPref("flock.favorites.starShowProperties");
- $("showDialog").checked = starShowProperties;
-
-
- // Reset the |id| attribute on the toolbar folder attribute to the URI of the
- // Bookmarks toolbar folder.
-
-
- /* if (MicrosummaryPicker.enabled)
- MicrosummaryPicker.init();
- */
- }
-
- function onToggleShowDialog()
- {
- var prefsService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
- prefsService.setBoolPref("flock.favorites.starShowProperties", $("showDialog").checked);
- }
-
- function initTitle()
- {
- if(gArg.bBookmarkAllTabs)
- document.title = document.getElementById("bookmarksBundle").getString("bookmarkAllTabsTitle");
- else
- document.title = document.getElementById("bookmarksBundle").getString("bookmarkCurTabTitle");
- }
-
- function onFieldInput()
- {
- var ok = document.documentElement.getButton("accept");
- ok.disabled = false;
- for (var i = 0; i < gRequiredFields.length; ++i) {
- if (gRequiredFields[i].value == "") {
- ok.disabled = true;
- return;
- }
- }
- }
-
-
- function onOK()
- {
- RDFC.Init(BMDS, gSelectedFolder);
-
- var url;
- var livemarkFeed = gArg.feedURL;
- if (gArg.bBookmarkAllTabs) {
- const groups = gArg.objGroup;
- // Local favorites
- if ($('createlocalcheck').checked) {
- gResource = BMDS.createFolderInContainer(gName.value, gSelectedFolder, -1);
- var tags = (gTags) ? gTags.getValue() : '';
- for (var i = 0; i < groups.length; ++i) {
- url = getNormalizedURL(groups[i].url);
- if ($("description").value != 'undefined' &&
- $("description").value != '')
- {
- groups[i].description = $("description").value;
- }
- BMDS.addBookmarkToFolder(gResource.Value, groups[i].name, url,
- gKeyword.value, groups[i].description,
- groups[i].charset, gPostData, tags);
- }
- }
- // Online favorites
- var bookmarks = groups.map(function(x){
- var bookmark = new Bookmark();
- bookmark.URL = x.url;
- bookmark.name = x.name;
- bookmark.tags = $("tags").value;
- bookmark.description = x.description;
- return bookmark;
- });
- bgPublishAll(bookmarks, $('bmServices-box'), gArg.listener);
- } else if (livemarkFeed != null) {
- url = getNormalizedURL(gArg.url);
- gResource = BMDS.createLivemarkInContainer(gName.value, url, livemarkFeed,
- gArg.description,
- gSelectedFolder, -1);
- } else {
- url = getNormalizedURL(gArg.url);
-
- var name = gName.value;
- var tags = (gTags)?gTags.getValue():'';
-
- // If the microsummary picker is enabled, the value of the name field
- // won't necessarily contain the user-entered name for the bookmark.
- // But the first item in the microsummary drop-down menu will always
- // contain the user-entered name, so get the name from there instead.
- /* if (MicrosummaryPicker.enabled) {
- var menuPopup = document.getElementById("microsummaryMenuPopup");
- name = menuPopup.childNodes[0].getAttribute("label");
- }
- // saveOverlayData(BMDS, gResource);
- */
- if ($('createlocalcheck').checked) {
- gResource = BMDS.createBookmarkWithTags(name, url, gKeyword.value,
- gDescription.value, gArg.charset,
- gPostData,tags);
- var selection = BookmarksUtils.getSelectionFromResource(gResource);
- var target = BookmarksUtils.getTargetFromFolder(gSelectedFolder);
-
- BookmarksUtils.insertAndCheckSelection("newbookmark", selection, target);
- /*
- if (MicrosummaryPicker.enabled) {
- MicrosummaryPicker.commit();
- MicrosummaryPicker.destroy();
- }
- */
- if (gArg.bWebPanel && gResource) {
- // Assert that we're a web panel.
- BMDS.Assert(gResource, RDF.GetResource(gNC_NS+"WebPanel"),
- RDF.GetLiteral("true"), true);
- }
- }
-
- // Publish to online service (if needed)
- var bookmark = new Bookmark();
- bookmark.URL = getNormalizedURL(gUrl);
- bookmark.name = $("name").value;
- bookmark.tags = $("tags").value;
- bookmark.description = $("description").value;
-
- bgPublishAll([bookmark], $('bmServices-box'), gArg.listener);
- }
-
- setDoEverytime();
-
- // return list of all online bm services that the url
- // was published to
- gArg.publishList = [];
- var servicesBox = $('bmServices-box');
- var children = servicesBox.childNodes;
- for (var i = 0; i < children.length; i++)
- {
- var accountItem = children.item(i).firstChild;
- if (accountItem.checked) {
- gArg.publishList.push(accountItem.serviceId + "--" + accountItem.accountId);
- }
- }
-
- // in insertSelection, the ds flush is delayed. It will never be performed,
- // since this dialog is destroyed before.
- // We have to flush manually
- var remoteDS = BMDS.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
- remoteDS.Flush();
-
- var obs = Components.classes["@mozilla.org/observer-service;1"]
- .getService(Components.interfaces.nsIObserverService);
- obs.notifyObservers(window, 'favorites', 'favorites:update');
- }
-
- function onCancel()
- {
- // Destroy the microsummary picker controller to prevent memory leaks,
- // catching exceptions so we don't prevent the dialog from closing.
- try {
- if (MicrosummaryPicker.enabled)
- MicrosummaryPicker.destroy();
- }
- catch(e) {
- Components.utils.reportError(e);
- }
-
- return true;
- }
-
- function getNormalizedURL(url)
- {
- // Check to see if the item is a local directory path, and if so, convert
- // to a file URL so that aggregation with rdf:files works
- try {
- const kLF = Components.classes["@mozilla.org/file/local;1"]
- .createInstance(Components.interfaces.nsILocalFile);
- kLF.initWithPath(url);
- if (kLF.exists()) {
- var ioService = Components.classes["@mozilla.org/network/io-service;1"]
- .getService(Components.interfaces.nsIIOService);
- var fileHandler = ioService.getProtocolHandler("file")
- .QueryInterface(Components.interfaces.nsIFileProtocolHandler);
-
- url = fileHandler.getURLSpecFromFile(kLF);
- }
- }
- catch (e) {
- }
-
- return url;
- }
-
-
-
-